package md.lanjing.com.module_home.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.ToastUtils;

import md.lanjing.com.module_home.api.HomeApiService;
import md.lanjing.com.module_home.bean.RegisterRequest;
import md.lanjing.com.module_home.bean.RegisterResponse;
import md.lanjing.com.module_home.bean.RegisterSecurityCodeRequest;
import md.lanjing.com.module_home.bean.RegisterSecurityCodeResponse;
import retrofit2.Call;
import retrofit2.Response;

public class RegisterContact {
    public static class RegisterPresent extends BasePresent<IRegisterView> {
        public void register(final Context context, String tel, String securityCode, String loginPwd, String inviteCode, String dealPwd) {
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            RegisterRequest request=new RegisterRequest(tel, securityCode, Md5Utils.stringToMD5(loginPwd), Md5Utils.stringToMD5(dealPwd),inviteCode);
            service.register(request).enqueue(new NetCallBack<RegisterResponse>() {
                @Override
                public void onSuccess(Call<RegisterResponse> call, Response<RegisterResponse> response) {
                    if (getView()!=null){
                        getView().getRegisterData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }

        public void getRegisterSecurityCode(final Context context,String phone){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            RegisterSecurityCodeRequest request=new RegisterSecurityCodeRequest(phone,1);
            service.getRegisterSecurityCode(request).enqueue(new NetCallBack<RegisterSecurityCodeResponse>() {
                @Override
                public void onSuccess(Call<RegisterSecurityCodeResponse> call, Response<RegisterSecurityCodeResponse> response) {
                    if (getView()!=null){
                        getView().getRegisterSecurityCodeData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }
    }

    public interface IRegisterView extends IBaseView {
        void getRegisterData(Response<RegisterResponse> response);
        void getRegisterSecurityCodeData(Response<RegisterSecurityCodeResponse> response);
    }
}
